package com.cs.sso.service.impl;

import com.cs.common.json.JsonUtil;
import com.cs.common.sequence.UUIDGenerator;
import com.cs.sso.exception.LoginException;
import com.cs.sso.service.TokenService;
import com.cs.sso.vo.LoginToken;
import com.fasterxml.jackson.core.JsonProcessingException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

@Service
@Slf4j
public class TokenServiceImpl implements TokenService {
    @Autowired
    private RedisTemplate redisTemplate;

    private String tokenString = "SSO_TOKEN_%s";

    @Override
    public LoginToken check(String token) {
        LoginToken loginToken = (LoginToken) redisTemplate.opsForValue().get(token);
        return loginToken;
    }

    @Override
    public String getToken() {
        String uuid = UUIDGenerator.getUUID();
        return String.format(tokenString, uuid);
    }
}
